package com.java3_8;

public class ThreadTake implements Runnable {
    private TotalDish dish;

    public ThreadTake() {
    }

    public ThreadTake(TotalDish dish) {
        this.dish = dish;
    }

    @Override
    public void run() {
        //为了让该线程一直进行
        while (true) {
            synchronized (TotalDish.class) {
                while (dish.getDish() <= 0) {
                    try {
                        TotalDish.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                dish.delDish();
                System.out.println("菜品被送出一份，现在剩余的菜还有" + Thread.currentThread().getName() +dish.getDish() + "份");
                TotalDish.class.notifyAll();
            }
        }


    }
}
